<!DOCTYPE html>
<html>
<head>
    <meta charset="utf-8">
    <title>Title</title>
    <meta name="viewport" content="width=device-width, initial-scale=1.0,maximum-scale=1.0, user-scalable=no"/>
    <meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1"/>
    <meta name="renderer" content="webkit">
    <link rel="stylesheet" href="../mdui/css/mdui.min.css">
    <script defer src="../mdui/js/mdui.min.js"></script>
    <script src="../js/axios.min.js"></script>
    <script src="../js/qs.min.js"></script>
    <script src="../js/common.js"></script>
    <script src="../js/vue.js"></script>
    <style>
    </style>
</head>
<body class="mdui-theme-primary-indigo mdui-theme-accent-green">
<div class="mdui-container-fluid" id="app">
    <h1 class="mdui-text-color-theme">所有催单</h1>
    <div>
        <table class="mdui-table mdui-table-hoverable">
            <thead>
            <tr>
                <th>状态</th>
                <th>详情</th>
                <th>地点</th>
                <th>提交时间</th>
                <th>同意取消</th>
                <th>拒绝取消</th>
                <th>查阅详情</th>
            </tr>
            </thead>
            <tbody>
            <tr v-for="(r,index) in repair">
                <td>{{r.status |fmtGenter}}</td>
                <td>{{r.detail}}</td>
                <td>{{r.place}}</td>
                <td>{{r.urgenlist[0].createTime}}</td>
                <td>
                    <button class="mdui-btn mdui-btn-raised mdui-ripple mdui-color-theme-accent"
                            @click="deleteRepair(r.id,index)">同意取消
                    </button>
                </td>
                <td>
                    <button class="mdui-btn mdui-btn-raised mdui-ripple mdui-color-theme-accent"
                            @click="updateUrgent(r.urgenlist[0].id,r.id,index)">重新催单
                    </button>
                </td>
                <td><a :href="'../repair/detail.html?id='+r.id"> 查看 </a>
                </td>
            </tr>
            </tbody>
        </table>
    </div>
</div>
<script>
    let vm = new Vue({
        el: '#app',
        data: {
            id: '',
            place: '',
            repair: [],
        },
        created() {
            this.findrepaires();
        },
        filters: {
            fmtGenter(val) {
                if (val == 1) {
                    return "待管理员查看"
                } else if (val == 2) {
                    return "已查看"
                } else if (val == 3) {
                    return "待同意取消"
                } else if (val == 4) {
                    return "已同意取消"
                } else if (val == 5) {
                    return "待验收"
                } else if (val == 5) {
                    return "已验收"
                }
            }
        },
        methods: {
            updateUrgent(uid, rid, index) {
                console.log(this.name)
                let _this = this
                axios.get("/urgent/updateUrgent1", {
                    params: {
                        uid: uid,
                        rid: rid
                    }
                })
                    .then(function (res) {
                        if (res.data) {
                            mdui.alert("催单成功")
                            _this.findrepaires();

                        }
                    })
            },

            findrepaires() {
                let _this = this;
                axios
                    .get("/repair/findByStatus")
                    .then(function (res) {
                        _this.repair = res.data;
                        console.log(_this.repair)
                    })
            },

            deleteRepair(rid, index) //rid传到后台后台正确删除后 根据index移除数组中对应的数据
            {
                console.log(123)
                let _this = this;
                axios.delete("/urgent/deleteRepair/" + rid)
                    .then(function (res) {
                        if (res.data.success) {
                            mdui.alert("取消成功");
                            _this.repair.splice(index, 1)
                        }
                    })
            },

        }
    })
</script>
</body>
</html>